import { defineStore } from 'pinia'

export const useUserStore = defineStore('user', {
  state: () => ({
    name: '默认用户',
    age: 0,
    isLoggedIn: false
  }),
  
  getters: {
    displayName: (state) => {
      return state.isLoggedIn ? state.name : '访客'
    },
    
    isAdult: (state) => {
      return state.age >= 18
    }
  },
  
  actions: {
    login(name, age) {
      this.name = name
      this.age = age
      this.isLoggedIn = true
    },
    
    logout() {
      this.name = '默认用户'
      this.age = 0
      this.isLoggedIn = false
    },
    
    updateAge(newAge) {
      this.age = newAge
    }
  }
})